#include "measure.h"
#include "ui_measure.h"
#include "customitem.h"
#include <QVariant>
#include <QMessageBox>
#include <QFileDialog>
#include <QInputDialog>
#include <QDebug>
#include "cjson/CJsonObject.hpp"

Measure::Measure(CSql* sql,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Measure),
    m_Sql(sql)
{
    ui->setupUi(this);

    this->setWindowTitle(_("SolutionSet"));

    ui->tbPrjAdd->setToolTip(_("Add"));
    ui->tbPrjAdd->setIcon(QIcon(":/images/Add.png"));
    ui->tbPrjAdd->setIconSize(QSize(16, 16));
    ui->tbPrjAdd->setObjectName("tbPrjAdd");
    ui->tbPrjDel->setToolTip(_("Del"));
    ui->tbPrjDel->setIcon(QIcon(":/images/Erase.png"));
    ui->tbPrjDel->setIconSize(QSize(16, 16));
    ui->tbPrjDel->setObjectName("tbPrjDel");

    ui->tbLayerAdd->setToolTip(_("Add"));
    ui->tbLayerAdd->setIcon(QIcon(":/images/Add.png"));
    ui->tbLayerAdd->setIconSize(QSize(16, 16));
    ui->tbLayerAdd->setObjectName("tbLayerAdd");
    ui->tbLayerDel->setToolTip(_("Del"));
    ui->tbLayerDel->setIcon(QIcon(":/images/Erase.png"));
    ui->tbLayerDel->setIconSize(QSize(16, 16));
    ui->tbLayerDel->setObjectName("tbLayerDel");

    ui->tbAdd->setToolTip(_("Add"));
    ui->tbAdd->setIcon(QIcon(":/images/Add.png"));
    ui->tbAdd->setIconSize(QSize(16, 16));
    ui->tbAdd->setObjectName("tbAdd");
    ui->tbDel->setToolTip(_("Del"));
    ui->tbDel->setIcon(QIcon(":/images/Erase.png"));
    ui->tbDel->setIconSize(QSize(16, 16));
    ui->tbDel->setObjectName("tbDel");

    ui->tbSave->setToolTip(_("Save"));
    ui->tbSave->setIcon(QIcon(":/images/Apply.png"));
    ui->tbSave->setIconSize(QSize(16, 16));
    ui->tbSave->setObjectName("tbSave");
    ui->tbCancel->setToolTip(_("Cancel"));
    ui->tbCancel->setIcon(QIcon(":/images/Cancel.png"));
    ui->tbCancel->setIconSize(QSize(16, 16));
    ui->tbCancel->setObjectName("tbCancel");

    ui->tbSave->setEnabled(false);
    ui->tbCancel->setEnabled(false);

    connect(ui->tbPrjAdd, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbPrjDel, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbLayerAdd, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbLayerDel, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbAdd, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbDel, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbSave, SIGNAL(clicked()), this, SLOT(myCommond()));
    connect(ui->tbCancel, SIGNAL(clicked()), this, SLOT(myCommond()));

    ui->tableWidget->setColumnCount(5);

    //QTableWidgetItem* item = new QTableWidgetItem("some header", 0);
    //item->setFlags(Qt::ItemIsEditable);
    //ui->tableWidget->setItem(0,0,item);
    //ui->tableWidget->setVerticalHeaderItem(0, item);
    ///


    connect(ui->tableWidget,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(cellDBClicked(int,int)));
    connect(ui->cmbPrj,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
    connect(ui->cmbLayer,SIGNAL(currentIndexChanged(int)),this,SLOT(onLayerCurrentIndexChanged(int)));

    //projet
    showPrj();
    showLayer(0);
    showPara();



     addint = -1;
}

Measure::~Measure()
{
    delete ui;
}
void Measure::showPrj()
{
    QStringList items;
    NODE nd;
    NODE rds;
    std::string value;
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
    items.clear();
    RECORDSET rd = m_Sql->RecordSet("select * from fsapp");
    ui->cmbPrj->clear();

    if(rd.size()>0){
        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["value"];
            items << QString::fromLocal8Bit(value.c_str());
            //rds[value] = nd["para"];
            //qDebug() << QString::fromLocal8Bit(value.c_str());
        }
    }
    ui->cmbPrj->addItems(items);
}

void Measure::showLayer(int idx)
{
    QStringList items;
    NODE nd;
    NODE rds;
    std::string value;
    items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter");
    items.clear();
    ui->cmbLayer->clear();
    RECORDSET rd = m_Sql->RecordSet(QString("select * from fslayer where fsapp = '%1' ").arg(ui->cmbPrj->itemText(idx)).toStdString());

    if(rd.size()>0){
        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["value"];
            items << QString::fromLocal8Bit(value.c_str());
            //rds[value] = nd["para"];
            //qDebug() << QString::fromLocal8Bit(value.c_str());
        }
    }
    ui->cmbLayer->addItems(items);
}

std::string MeasureFmt(std::string me)
{
    std::string ret = me;

    size_t a,b;
    b = me.length()-1;
    a = me.find('.');

    //qDebug()<< a << b;
    if(a==string::npos){
        ret.append(".0");
    }
    else if(a==b){
        ret.append("0");
    }

    return ret;
}
void Measure::showPara()
{
    QStringList items;
    NODE nd;
    NODE rds;
    int idx1,idx2,row=0;
    idx1 = ui->cmbPrj->currentIndex();
    idx2 = ui->cmbLayer->currentIndex();

    QTableWidgetItem* item =nullptr;;
    std::string value;
    QString sql;
    sql = QString("select * from fspoint where fsapp = '%1' and layer = '%2'").arg(ui->cmbPrj->itemText(idx1)).arg(ui->cmbLayer->itemText(idx2));
    RECORDSET rd = m_Sql->RecordSet(sql.toStdString());
    ui->tableWidget->clear();

    QStringList headL;
    headL << "名称"<<"Gap-std"<<"Gap-"<<"Gap+"<<"Flush"<<"Flush-"<<"Flush+";
    ui->tableWidget->setColumnCount(headL.size());
    ui->tableWidget->setHorizontalHeaderLabels(headL);

    //QRegExp regexp_DDD("^(\\d+)(\\.){0,1}(\\d+)$");
    QRegExp regexp_DDD("^(\\d+\\.{1}\\d+)$");
    QRegExp regexp_0To255("^(0|[1-9]{1,2}|[1]\\d{0,2}|2[0-4]\\d|255)$");
    QRegExp regexp_0To128("^(0|[1-9]{1,2}|[1][0-2][0-8])$");
    for(int row = 1; row < headL.size(); row++)
    {
         ui->tableWidget->setItemDelegateForColumn(row, new CustomItemDelegrate(regexp_DDD,ui->tableWidget));
         ui->tableWidget->setColumnWidth(row,60);
    }


    ui->tableWidget->setRowCount(rd.size());
    if(rd.size()>0){

        for(RECORDSET::iterator it = rd.begin();it!=rd.end();it++){
        //for(int i = 0;i<rd.size();i++){
            nd =  *it;
            value = nd["id"];
            items << QString::fromLocal8Bit(value.c_str());
            value = MeasureFmt(nd["gap"]);
            items << QString::fromLocal8Bit(value.c_str());
            value = nd["gapmin"];
            items << QString::fromLocal8Bit(value.c_str());
            value = nd["gapmax"];
            items << QString::fromLocal8Bit(value.c_str());
            value = nd["flush"];
            items << QString::fromLocal8Bit(value.c_str());
            value = nd["flushmin"];
            items << QString::fromLocal8Bit(value.c_str());
            value = nd["flushmax"];
            items << QString::fromLocal8Bit(value.c_str());

            for(int col = 0;col<headL.size();col++){
                item = new QTableWidgetItem(items.at(col), 0);
                if(col==0)
                    item->setFlags(Qt::ItemIsEditable);
                ui->tableWidget->setItem(row,col,item);
            }
            row++;
            items.clear();



            //items << QString::fromLocal8Bit(value.c_str());
            //rds[value] = nd["para"];
            //qDebug() << QString::fromLocal8Bit(value.c_str());
        }
    }


}


void Measure::myCommond()
{
    QString obj = sender()->objectName();
    int idx1,idx2;
    idx1 = ui->cmbPrj->currentIndex();
    idx2 = ui->cmbLayer->currentIndex();
    qDebug()<<obj<< idx1 << idx2;


    QTableWidgetItem* item;
    if(obj == "tbPrjAdd"){
        bool ok;
        QString qsql;
        std::string sql;
        //QString text=QInputDialog::getText(this,tr("新建工程"),tr("请输入新建工程名称："),QLineEdit::Normal,"",&ok);

        QString text = MSGINF::MsgGetText(this,_("New Project"),_("Input Project Name Please."),&ok);

        if(ok && !text.isEmpty()){
            qsql = QString("select value from fsapp where value = '%1'").arg(text);
            RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());
            if(rd.size()>0){
                //QMessageBox box(QMessageBox::Warning,"警告","工程名已存！");
                //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
                //box.setStandardButtons (QMessageBox::Ok);
                //box.setButtonText (QMessageBox::Ok,QString("确 定"));
                //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
                //box.exec();
                MSGINF::MsgShowOk(this,_("Warning"),_("Project Is Exist."));
            }
            else{
                qsql = QString("insert into fsapp(value) values('%1')").arg(text);
                m_Sql->exeSql(qsql.toStdString());
                qsql = QString("insert into fslayer(value,fsapp) values('default','%1')").arg(text);
                m_Sql->exeSql(qsql.toStdString());

                showPrj();
            }

        }
    }
    else if(obj == "tbPrjDel"){
        if(idx1>=0){
            //QString str = QString("确认删除工程【%1】的所有信息！").arg(ui->cmbPrj->itemText(idx1));
            QString str = QString(_("Are you sure delete(%1)?")).arg(ui->cmbPrj->itemText(idx1));
            //QMessageBox box(QMessageBox::Warning,"警告",str);
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            //box.setStandardButtons (QMessageBox::Ok);
            //box.setButtonText (QMessageBox::Ok,QString("确 定"));
            //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
            //if(box.exec() == QMessageBox::Ok){
            int bexec = MSGINF::MsgShowOk(this,_("Warning"),str,QMessageBox::Ok|QMessageBox::Cancel);
            if(bexec == QMessageBox::Ok){
                str = QString("delete from fspoint where fsapp='%1'").arg(ui->cmbPrj->itemText(idx1));
                m_Sql->exeSql(str.toStdString());
                str = QString("delete from fslayer where fsapp='%1'").arg(ui->cmbPrj->itemText(idx1));
                m_Sql->exeSql(str.toStdString());
                str = QString("delete from fsapp where value='%1'").arg(ui->cmbPrj->itemText(idx1));
                m_Sql->exeSql(str.toStdString());
                showPrj();

            }

        }
    }
    else if(obj == "tbLayerAdd"){
        bool ok;
        QString qsql;
        std::string sql;
        if(idx1<0){
            /*
            QMessageBox box(QMessageBox::Warning,"警告","没有工程,请先添加工程！");
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            box.setStandardButtons (QMessageBox::Ok);
            box.setButtonText (QMessageBox::Ok,QString("确 定"));
            box.setButtonText (QMessageBox::Cancel,QString("取 消"));
            box.exec();
            */
            MSGINF::MsgShowOk(this,_("Warning"),_("No have Project,First Add Project Please."));
            return;

        }

        //QString text=QInputDialog::getText(this,tr("新建图层"),tr("请输入图层名称："),QLineEdit::Normal,"",&ok);
        QString text= MSGINF::MsgGetText(this,_("New Layer"),_("Input Layer Name Please"),&ok);
        if(ok && !text.isEmpty()){
            qsql = QString("select value from fslayer where value = '%1' and fsapp = '%2'").arg(text).arg(ui->cmbPrj->itemText(idx1));
            RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());
            if(rd.size()>0){
                //QMessageBox box(QMessageBox::Warning,"警告","图层名已存！");
                //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
                //box.setStandardButtons (QMessageBox::Ok);
                //box.setButtonText (QMessageBox::Ok,QString("确 定"));
                //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
                //box.exec();
                MSGINF::MsgShowOk(this,_("Warning"),_("Layer Name Exist."));
            }
            else{
                qsql = QString("insert into fslayer(value,fsapp) values('%1','%2')").arg(text).arg(ui->cmbPrj->itemText(idx1));;
                m_Sql->exeSql(qsql.toStdString());
                showLayer(idx1);
            }
        }

    }
    else if(obj == "tbLayerDel"){
        if(idx2>=0){
            //QString str = QString("确认删除工程【%1】的【%2】图层所有信息！")
            //        .arg(ui->cmbPrj->itemText(idx1))
            //        .arg(ui->cmbLayer->itemText(idx2));
            QString str = QString(_("Are you sure delete project(%1) of layer(%2)?"))
                    .arg(ui->cmbPrj->itemText(idx1))
                    .arg(ui->cmbLayer->itemText(idx2));

            if(ui->cmbLayer->itemText(idx2)=="default"){
                MSGINF::MsgShowOk(this,_("Warning"),_("Cann't Delete 'default' layer!"),QMessageBox::Ok);
                return ;
            }

            //QMessageBox box(QMessageBox::Warning,"警告",str);
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            //box.setStandardButtons (QMessageBox::Ok);
            //box.setButtonText (QMessageBox::Ok,QString("确 定"));
            //box.setButtonText (QMessageBox::Cancel,QString("取 消"));

            int bexec = MSGINF::MsgShowOk(this,_("Warning"),str,QMessageBox::Ok|QMessageBox::Cancel);
            //if(box.exec() == QMessageBox::Ok){
            if(bexec == QMessageBox::Ok){
                str = QString("delete from fspoint where fsapp='%1' and layer='%2'")
                        .arg(ui->cmbPrj->itemText(idx1))
                        .arg(ui->cmbLayer->itemText(idx2));
                m_Sql->exeSql(str.toStdString());
                str = QString("delete from fslayer where fsapp='%1' and value='%2'")
                        .arg(ui->cmbPrj->itemText(idx1))
                        .arg(ui->cmbLayer->itemText(idx2));
                m_Sql->exeSql(str.toStdString());
                //str = QString("delete from fsapp where value='%1'").arg(ui->cmbPrj->itemText(idx1));
                //m_Sql->exeSql(str.toStdString());
                //showPrj();
                showLayer(idx1);

            }

        }

    }
    else if(obj == "tbAdd"){
        if(idx1<0 || idx2<0){
            //QMessageBox box(QMessageBox::Warning,"警告","没有工程或图层,请先添加工程或图层！");
            //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
            //box.setStandardButtons (QMessageBox::Ok);
            //box.setButtonText (QMessageBox::Ok,QString("确 定"));
            //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
            //box.exec();
            MSGINF::MsgShowOk(this,_("Warning"),_("Projec Or Layer is Empty,First Add Project Or Layer"));
            return;

        }
        else{
            bool ok;
            QString qsql;

            //QString text=QInputDialog::getText(this,tr("新建测量点"),tr("请输入测量点名称："),QLineEdit::Normal,"",&ok);
            QString text=MSGINF::MsgGetText(this,_("New Measur"),_("Please Input Measure"),&ok);
            if(ok && !text.isEmpty()){
                //qsql = QString("select * from fspoint where id='%1' and layer = '%2' and fsapp = '%3'")
                //        .arg(text)
                //        .arg(ui->cmbLayer->itemText(idx2))
                //        .arg(ui->cmbPrj->itemText(idx1));
                qsql = QString("select * from fspoint where id='%1' and fsapp = '%2'")
                        .arg(text)
                        .arg(ui->cmbPrj->itemText(idx1));;
                RECORDSET rd = m_Sql->RecordSet(qsql.toStdString());
                if(rd.size()>0){
                    //QMessageBox box(QMessageBox::Warning,"警告","测量点存在！");
                    //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
                    //box.setStandardButtons (QMessageBox::Ok);
                    //box.setButtonText (QMessageBox::Ok,QString("确 定"));
                    //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
                    //box.exec();
                    MSGINF::MsgShowOk(this,_("Warning"),_("Measure is exist"));
                    return;
                }
            }
            else
                return;


            ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
            ui->tbAdd->setEnabled(false);
            ui->tbDel->setEnabled(false);
            ui->tbSave->setEnabled(true);
            ui->tbCancel->setEnabled(true);
            addint = ui->tableWidget->rowCount()-1;

            QTableWidgetItem* item = new QTableWidgetItem(text, 0);
            item->setFlags(Qt::ItemIsEditable);
            ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,0,item);

            for(int col = 1;col<ui->tableWidget->columnCount() ;col++){
                item = new QTableWidgetItem("0.0", 0);
                ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,col,item);
            }

        }
    }
    else if(obj == "tbDel"){
        if(ui->tableWidget->currentRow()<0)
            return;

        int row = ui->tableWidget->currentRow();
        QString sql;
        sql = QString("delete from fspoint where id='%1' and layer = '%2' and fsapp = '%3'")
                .arg(ui->tableWidget->item(row,0)->text())
                .arg(ui->cmbLayer->itemText(idx2))
                .arg(ui->cmbPrj->itemText(idx1));
        qDebug()<< sql;

        delmap[ui->tableWidget->item(row,0)->text().toStdString()] = sql.toStdString();

        ui->tableWidget->removeRow(ui->tableWidget->currentRow());
        ui->tbAdd->setEnabled(false);
        ui->cmbLayer->setEnabled(false);
        ui->cmbPrj->setEnabled(false);
        ui->tbSave->setEnabled(true);
        ui->tbCancel->setEnabled(true);
    }
    else if(obj == "tbSave"){
        item =  ui->tableWidget->item(0,1);
        //QVariant vt = ui->tableWidget->item(0,1)->data(Qt::EditRole);
        QString str;
        if(item != nullptr)
            str = item->text();

        if(!doSave())
            return;


        ui->tbAdd->setEnabled(true);
        ui->tbDel->setEnabled(true);
        ui->cmbLayer->setEnabled(true);
        ui->cmbPrj->setEnabled(true);
        ui->tbSave->setEnabled(false);
        ui->tbCancel->setEnabled(false);

        addint = -1;
        delmap.clear();
        modifymap.clear();
        showPara();
    }
    else if(obj == "tbCancel"){
        ui->tbAdd->setEnabled(true);
        ui->tbDel->setEnabled(true);
        ui->cmbLayer->setEnabled(true);
        ui->cmbPrj->setEnabled(true);

        ui->tbSave->setEnabled(false);
        ui->tbCancel->setEnabled(false);

        addint = -1;
        delmap.clear();
        modifymap.clear();
        showPara();
    }

}

void Measure::cellDBClicked(int row, int column)
{
    //qDebug()<< __FUNCTION__ << row << column;
    ui->tbAdd->setEnabled(false);
    ui->tbDel->setEnabled(false);
    ui->tbSave->setEnabled(true);
    ui->tbCancel->setEnabled(true);
    if(addint != row)
        modifymap[row] = "";
}

void Measure::onCurrentIndexChanged(int idx)
{
    //qDebug()<< __FUNCTION__ << idx;
    showLayer(idx);
    //showPara();
}
void Measure::onLayerCurrentIndexChanged(int idx)
{
    //qDebug()<< __FUNCTION__ << idx;
    //showLayer(idx);
    showPara();
}
bool Measure::doSave()
{
    QTableWidgetItem* item;
    QStringList strlist;
    QString sql;
    int idx1 = ui->cmbPrj->currentIndex();
    int idx2 = ui->cmbLayer->currentIndex();
    if( addint != -1){
        for(int col = 0;col<7;col++){
            item =  ui->tableWidget->item(addint,col);
            //QVariant vt = ui->tableWidget->item(0,1)->data(Qt::EditRole);

            if(item != nullptr)
                strlist << item->text();
            else{
                strlist.clear();
                //QMessageBox box(QMessageBox::Warning,"警告","测量点数据不能为空，请输入数据！");
                //box.setStandardButtons (QMessageBox::Ok|QMessageBox::Cancel);
                //box.setStandardButtons (QMessageBox::Ok);
                //box.setButtonText (QMessageBox::Ok,QString("确 定"));
                //box.setButtonText (QMessageBox::Cancel,QString("取 消"));
                //box.exec();
                MSGINF::MsgShowOk(this,_("Warning"),_("Measure isn't empty."));
                return false;

            }
        }
        if(strlist.count()>0){

            //"名称"<<"Gap-std"<<"Gap+"<<"Gap-"<<"Flush"<<"flushmin"<<"flushmax";
            sql = QString("insert into fspoint(id,gap,gapmin,gapmax,flush,flushmin,flushmax,layer,fsapp) "
                          "values('%1','%2','%3','%4','%5','%6','%7','%8','%9')")
                    .arg(strlist.at(0)).arg(strlist.at(1)).arg(strlist.at(2)).arg(strlist.at(3)).arg(strlist.at(4))
                    .arg(strlist.at(5)).arg(strlist.at(6))
                    .arg(ui->cmbLayer->itemText(idx2)).arg(ui->cmbPrj->itemText(idx1));

            qDebug()<<sql;
            m_Sql->exeSql(sql.toStdString());

        }
    }

    int a;
    std::string delMeasure;
    QString str,layer,prj;
    int tp;
    neb::CJsonObject cjs,ndcjs;
    std::string  stdPic="",pin;

    layer = ui->cmbLayer->itemText(ui->cmbLayer->currentIndex());
    prj = ui->cmbPrj->itemText(ui->cmbPrj->currentIndex());

    for (const auto& n : delmap) {
        delMeasure = n.first;
        qDebug() << delMeasure.c_str();
        str = n.second.c_str();
        //qDebug() << a << " = " << str << "; ";
        m_Sql->exeSql(str.toStdString());
        str = QString("select * from fslayer where value ='%1' and fsapp='%2';").arg(layer,prj);
        RECORDSET rd = m_Sql->RecordSet(str.toStdString());
        if(rd.size()>0){
            str = rd.front()["para"].c_str();
            qDebug() << str;

            if(cjs.Parse(str.toStdString())){
                for(int i=0;i<cjs["shape"].GetArraySize();i++){
                    ndcjs.Clear();
                    cjs["shape"].Get(i,ndcjs);
                    ndcjs.Get("type",tp);
                    if(tp == 0){
                        ndcjs.Get("point",pin);
                        if(pin == delMeasure){
                            qDebug() << pin.c_str();
                            cjs["shape"].Delete(i);
                            qDebug()<< cjs.ToString().c_str();
                            str = QString("update fslayer set para='%1' where value ='%2' and fsapp='%3';")
                                    .arg(cjs.ToString().c_str(),layer,prj);
                            m_Sql->exeSql(str.toStdString());
                            break;
                        }
                    }

                }
            }
        }

    }
    for (const auto& n : modifymap) {
        a = n.first;
        str = QString("update fspoint set gap='%1',gapmin='%2',gapmax='%3',flush='%4',flushmin='%5',flushmax='%6' where id='%7' "
                      "and layer='%8' and fsapp='%9'")
                .arg(ui->tableWidget->item(a,1)->text())
                .arg(ui->tableWidget->item(a,2)->text())
                .arg(ui->tableWidget->item(a,3)->text())
                .arg(ui->tableWidget->item(a,4)->text())
                .arg(ui->tableWidget->item(a,5)->text())
                .arg(ui->tableWidget->item(a,6)->text())
                .arg(ui->tableWidget->item(a,0)->text())
                .arg(ui->cmbLayer->itemText(idx2))
                .arg(ui->cmbPrj->itemText(idx1));
        //qDebug() << a << " = " << str << "; ";
        m_Sql->exeSql(str.toStdString());
    }
    return true;
}
